package com.lanou.beautifulwardrobe.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TabHost;
import android.widget.Toast;

import com.android.volley.Response;
import com.bartoszlipinski.recyclerviewheader.RecyclerViewHeader;
import com.google.gson.Gson;
import com.lanou.beautifulwardrobe.Activity_zhuti.ActivityFragment;
import com.lanou.beautifulwardrobe.Brand.BrandFragment;
import com.lanou.beautifulwardrobe.Home.Adapter.HotlistRecyclerViewAdapter;
import com.lanou.beautifulwardrobe.Home.HomeFragment;
import com.lanou.beautifulwardrobe.R;
import com.lanou.beautifulwardrobe.Space.SpaceFragment;
import com.lanou.beautifulwardrobe.contants.Contants;
import com.lanou.beautifulwardrobe.contants.VolleySingleton;
import com.lanou.beautifulwardrobe.entify.HotlistLike;
import com.lanou.beautifulwardrobe.entify.HotlistResult;
import com.lanou.beautifulwardrobe.listener_interface.MyHotlistItemClickListener;

import java.util.List;

/**
 * Created by dllo on 15/11/2.
 */
public class HotListActivity extends FragmentActivity  implements View.OnClickListener, MyHotlistItemClickListener {
    private ImageButton hotListBack;
    private RecyclerView recyclerView;
    private HotlistRecyclerViewAdapter adapter;
    private GridLayoutManager manager;
    private VolleySingleton volleySingleton = VolleySingleton.getInstance();
    private RecyclerViewHeader header;
    private TabHost mHost;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recommend_hotlist_);
        initView();
        initData();
    }

    private void initView() {
        header = (RecyclerViewHeader) findViewById(R.id.hotlistHeader);
        hotListBack = (ImageButton) findViewById(R.id.hotListBack);
        recyclerView = (RecyclerView) findViewById(R.id.hotlistRecyclerView);
        adapter = new HotlistRecyclerViewAdapter();
        manager = new GridLayoutManager(this, 1);
        hotListBack.setOnClickListener(this);
    }

    private void initData() {
        recyclerView.setLayoutManager(manager);
        header.attachTo(recyclerView, true);
        volleySingleton.getStringRequset(Contants.HOTLIST_URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                HotlistResult hotlistResult = gson.fromJson(response, HotlistResult.class);
                if (hotlistResult != null) {
                    List<HotlistLike> hotlistLikeList = hotlistResult.getData().getLikes();
                    adapter.addData(hotlistLikeList);
                    recyclerView.setAdapter(adapter);
                }
            }
        });
        adapter.setOnMyHotlistItemClickListener(this);
    }

    @Override
    public void onClick(View v) {
        finish();
    }

    @Override
    public void onHotlistItemClick(String id) {
       // Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, ProductDetailActivity.class);
        intent.putExtra("id", id);
        startActivity(intent);
    }
}
